/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javafeiq.service.detect.util.impl;

import java.io.IOException;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafeiq.service.detect.util.DetectService;
import javafeiq.service.status.StatusConstant;

/**
 *
 * @author bitray
 */
public class TcpDetect implements DetectService {

    @Override
    public boolean isConnect(String ip) {
        boolean t = false;
        Socket socket = null;
        try {
            socket = new Socket(ip, StatusConstant.DEFAULT_PORT);
            socket.setSoTimeout(200);
            t = socket.isConnected();
        } catch (IOException ex) {
            Logger.getLogger(TcpDetect.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                if (socket != null) {
                    socket.close();
                }
            } catch (IOException ex) {
                Logger.getLogger(TcpDetect.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return t;
    }

    @Override
    public boolean sendInfo(String ip, String info) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

}
